#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

// 定义设备结构体，包含带宽和价格
struct Device
{
  int bandwidth;
  int price;
  // 重载比较运算符，按照带宽从大到小排序
  bool operator<(const Device &other) const
  {
    return bandwidth > other.bandwidth;
  }
};

// 计算在给定带宽限制下的总价格
int calculateTotalPrice(int bandwidth, const vector<vector<Device>> &devices)
{
  int totalPrice = 0;
  // 替换范围 for 循环为传统 for 循环
  for (size_t i = 0; i < devices.size(); ++i)
  {
    int minPrice = 1e9; // 初始化为一个较大的值
    // 替换范围 for 循环为传统 for 循环
    for (size_t j = 0; j < devices[i].size(); ++j)
    {
      if (devices[i][j].bandwidth >= bandwidth)
      {
        minPrice = min(minPrice, devices[i][j].price);
      }
    }
    if (minPrice == 1e9)
    {
      // 如果没有找到满足带宽限制的设备，返回一个很大的值
      return 1e9;
    }
    totalPrice += minPrice;
  }
  return totalPrice;
}

int main()
{
  int t;
  cin >> t;

  while (t--)
  {
    int n;
    cin >> n;
    vector<vector<Device>> devices(n);

    // 读取每个设备的制造商信息
    for (int i = 0; i < n; ++i)
    {
      int mi;
      cin >> mi;
      devices[i].resize(mi);
      for (int j = 0; j < mi; ++j)
      {
        cin >> devices[i][j].bandwidth >> devices[i][j].price;
      }
      // 对每个设备的制造商选项按照带宽从大到小排序
      sort(devices[i].begin(), devices[i].end());
    }

    int maxBandwidth = 0;
    // 替换范围 for 循环为传统 for 循环
    for (size_t i = 0; i < devices.size(); ++i)
    {
      if (devices[i].size() > 0)
      {
        maxBandwidth = max(maxBandwidth, devices[i][0].bandwidth);
      }
    }

    double maxRatio = 0.0;
    int left = 0, right = maxBandwidth;
    while (left <= right)
    {
      int mid = left + (right - left) / 2;
      int totalPrice = calculateTotalPrice(mid, devices);
      if (totalPrice != 1e9)
      {
        double currentRatio = static_cast<double>(mid) / totalPrice;
        maxRatio = max(maxRatio, currentRatio);
        left = mid + 1;
      }
      else
      {
        right = mid - 1;
      }
    }

    // 输出结果，保留三位小数
    cout << fixed << setprecision(3) << maxRatio << endl;
  }

  return 0;
}